package cn.wolf.wechat.util;

import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

public class AccessTokenUtil {

    private static RestTemplate template = new RestTemplate();

    public static JSONObject getAccessToken(){
        String strAccessToken = template.getForObject(TokenUtil.GET_ACCESS_TOKEN.replace("APPID", TokenUtil.APP_ID)
                .replace("APPSECRET", TokenUtil.APP_SECRET), String.class);
        return JSON.parseObject(strAccessToken);
    }
    public static void createInterface() throws UnsupportedEncodingException {
        String s = template.postForObject(TokenUtil.POST_CREATE_INTERFACE
                .replace("ACCES_TOKEN", getAccessToken().getString("access_token")),TokenUtil.JSON_INTERFACE.getBytes("utf-8"),String.class);
        System.out.println(s);
    }

}
